<template>
	<view style="height: 100vh; background-color: #FFFFFF;">
		<!-- 我的任务 -->
		<u-navbar title-color="#FFFFFF" height="48" back-icon-color="#FFFFFF" :border-bottom="false" :is-fixed="true" :title="'异常情况列表'"
			 :custom-back="back" ></u-navbar>
		<uc-content :loading="loading">
			<!--无数据列表页面-->
			<view v-if="fireHazardsList.length<1" class="view-center">
				<u-empty text="当前已无可反馈消防隐患,本次巡检结束,请返回首页" mode="list"></u-empty>
				<u-button @click="back" type="success" style="margin: 24rpx;">退回</u-button>
			</view>
			<view v-else>
				<view class="list-item" v-for="(item,index) in fireHazardsList" :key="index" @click="checkItem(item)">
					<view class="list-top ">
						<view class="list-left">{{ item.name }}</view>
					</view>
					<view class="list-center u-line-3">
						<view>生成时间: {{item.addTime | dateFormat }}</view>
					</view>
				</view>
				<u-loadmore :status="status" :icon-type="iconType" :load-text="loadText" />
			</view>
		</uc-content>
	
	</view>
</template>


<script>
	export default {
		data() {
			return {
				loading:false,
				fireHazardsList: [],
				pageNum:0,
				finished:false,
				status: 'loadmore',
				iconType: 'flower',
				loadText: {
					loadmore: '轻轻上拉',
					loading: '努力加载中',
					nomore: '没有更多数据了'
				},
				scrollTop:0,
				taskId:'',
			}
		},
		onPageScroll(e) {
			this.scrollTop = e.scrollTop;
		},
		onShow() {
			this.initView()
		},
		onLoad(e) {
			this.taskId=e.ucId
		},
		methods: {
			back(){
				if(this.fireHazardsList.length>0){
					uni.showToast({
					    title: '存在未反馈的消防隐患，不可进行返回操作',
						icon:"none",
					    duration: 2000
					});
				}else{
					window.native.back()
				}
			},
			initView() {
				this.loading=true
				this.fireHazardsList = [],
				this.pageNum = 0,
				this.getInNonEmergencyPage()
			},
			//获取火情隐患分页信息数据
			getInNonEmergencyPage(){
				this.pageNum++
				let _this = this
				return new Promise((resolve, reject) => {
					_this.utils.request("/api/app/inHiddenDanger/getNoFeedback", {taskId:this.taskId,pageNum:this.pageNum,pageSize:10}, "post", "app", true).then(res => {
						console.log(res)
						_this.fireHazardsList.push(...res.data.list)
						_this.finished = (res.data.pageNum >= res.data.pages);
						if(_this.finished){
							_this.status = 'nomore';
						}
						this.loading=false
						resolve(res)
					}).catch(error => {
						this.loading=false
						reject(error)
					})
				})
			},
			onReachBottom() {
				if(this.finished) return ;
				this.status = 'loading';
				this.getInNonEmergencyPage().then(res=>{
					if(this.finished) this.status = 'nomore';
					else this.status = 'loading';
				}).catch(error=>{
					this.status = 'nomore';
				})
			},
			checkItem(val){
				uni.navigateTo({
					url: "/pages/index/abnormal/info?ucId=" + val.ucId
				})
			}
		}
	}
</script>

<style>

</style>

